/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package module;

import wargame.entity.*;
import wargame.dao.*;

/**
 *
 * @author Clarence
 */
public class GameSetting {

//    public static void startGame() {
//
//        // Create Turn Information
//        TurnInformation ti = new TurnInformation();
//        ti.setPlayer_id(0);
//        ti.setCurrent_turn(0);
//        TurnInformationDAO.insertTurnInformation(ti);
//
//        // Unpause the Game.
//        GlobalDAO.pauseGame(false);
//
//
//        //
//
//
//    }
//
//    public static int getCurrentTurn() {
//       return TurnInformationDAO.getCurrentTurn();
//    }
//
//    public static boolean isPaused() {
//        return GlobalDAO.isGamePaused();
//    }
    public static int deductRental(Player p) {

        if (GameTurn.current_turn % GlobalConstant.RENTAL_TURN == 1) {
            int totalEmployee = EmployeeDAO.playerTotalEmployee(p);
            int rental = 0;
            
            if (totalEmployee == 0) {
                rental = GlobalConstant.RENTAL_COST;
            } else {
                rental = (int) (totalEmployee / GlobalConstant.RENTAL_CAPACITY) * GlobalConstant.RENTAL_COST;
            }

            Transaction t = new Transaction();
            t.setPlayer_id(p.getPlayer_id());
            t.setTurn(GameTurn.current_turn);
            t.setCredit_amount(rental);
            t.setDebit_amount(0);
            t.setDescription("Credit for rental payment");
            TransactionDAO tdao = new TransactionDAO();
            tdao.insertTransaction(t);

            return rental;
        }

        return 0;
    }

    public static int rentalNextTurn(Player p) {

        if ((GameTurn.current_turn + 1) % GlobalConstant.RENTAL_TURN == 1) {
            int totalEmployee = EmployeeDAO.playerTotalEmployee(p);
            int rental = (int) (totalEmployee / GlobalConstant.RENTAL_CAPACITY) * GlobalConstant.RENTAL_COST;
            return rental;
        }

        return 0;
    }
}
